/**
 * 应用持久模块
 */
define('store/ClientStore', ['WxCore','restTemplate'], function (wxCore,restTemplate) {

    const module= {
        storeName: 'ClientStore',
        namespaced: true,
        state: {},
        mutations: {},
        actions: {
            getValidateRule () {
                return {
                    clientSecret: [
                        { required: true, message: 'clientSecret不能为空', trigger: 'blur' }
                    ],
                    clientName: [
                        { required: true, message: '应用名称不能为空', trigger: 'blur' }
                    ]
                }
            },
            list ({ state, commit }, { pageIndex, pageSize }) {
                //console.log(this);
                return restTemplate.request({
                    url: '/api/OauthClient/list',
                    params: {
                        pageIndex,
                        pageSize
                    },
                    method: 'get'
                })
            },
            loadAll ({ state, commit }) {
                return restTemplate.request({
                    url: '/api/OauthClient/all',
                    method: 'get'
                })
            },
            save ({ state, commit }, vo) {
                const requestUrl = (vo.clientId && vo.clientId !== '') ? '/api/OauthClient/update' : '/api/OauthClient/add'
                return restTemplate.request({
                    url: requestUrl,
                    method: 'post',
                    data: vo
                })
            },
            delete ({ state, commit }, clientId) {
                return restTemplate.request({
                    url: 'api/OauthClient/delete',
                    method: 'post',
                    params: {id: clientId},
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded'
                    }
                })
            }
        }
    };
    return module;
})